#include<bits/stdc++.h>
using namespace std;
int main() {
    string str;
    getline(cin, str);
    int cur = 0;
    for (int i = 0; i < str.length(); i++) {
        if (str[i] == '6' ) {
            cur = i;
            while (str[i] == '6') i++;
            if (i - cur <= 3) {
                int k = i - cur;
                while (k--) {
                    cout << "6";
                }
            } else if (i - cur >= 4 && i - cur <= 9) {
                cout << "9";
            } else {
                cout << "27";
            }
            i--;
        } else {
            cout << str[i];
        }
    }
    cout << endl;
    return 0;
}